import Vue from 'vue';
import Router from 'vue-router';
import {
  sync
} from 'vuex-router-sync';
import App from '../../App.vue';
import store from '../../store';
import '@/style/base.scss';
import KboneUI from 'kbone-ui';
import 'kbone-ui/lib/weui/weui.css';
import kboneAPI from 'kbone-api';
import moment from 'moment';
import i18n from 'i18n';
import * as Promise from "bluebird";

import PaymentGoods from 'mpViews/paymentGoods';
import PaymentSuccess from 'mpViews/paymentGoods/paymentSuccess';
import PaymentAddress from 'mpViews/paymentAddress';
import AddAddress from 'mpViews/paymentAddress/addAddress';
import UpdateAddress from 'mpViews/paymentAddress/updateAddress';
import GoodsEvaluat from 'mpViews/goodsEvaluat';

Vue.use(Router);
Vue.use(KboneUI);
Vue.use(kboneAPI);

moment.locale('zh-cn');
Vue.prototype.$moment = moment;
Vue.prototype.i18n = i18n;

const router = new Router({
  mode: 'history',
  routes: [{
    path: '/paymentGoods/:orderId',
    name: 'paymentGoods',
    component: PaymentGoods
  }, {
    path: '/paymentSuccess',
    name: 'paymentSuccess',
    component: PaymentSuccess
  }, {
    path: '/paymentAddress',
    name: 'paymentAddress',
    component: PaymentAddress
  }, {
    path: '/addAddress',
    name: 'addAddress',
    component: AddAddress
  }, {
    path: '/updateAddress/:id',
    name: 'updateAddress',
    component: UpdateAddress
  }, {
    path: '/goodsEvaluat',
    name: 'goodsEvaluat',
    component: GoodsEvaluat
  }]
});

window.onShareAppMessage = function () {
  let href = window.location.href;
  let origin = window.location.origin;
  let url = href.substring(origin.length);
  return {
    path: url
  }
};

window.Promise = Promise;

export default function createApp() {
  const container = document.createElement('div');
  container.id = 'app';
  document.body.appendChild(container);

  Vue.config.productionTip = false;

  sync(store, router);

  return new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
  });
}
